package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import br.com.felix.fwt.ui.exception.ComponentRenderException;



/**
 * The Class PasswordBox implements the HTML input type=password.
 * The name attribute must be set if you want to retrieve the value (inputted by the user) after
 * a form submit.
 */
public class PasswordBox extends Input{

	private static final long serialVersionUID = -21136090245589886L;

	{
		this.cssClass = "fwtpasswordbox";
	}
	
	/**
	 * Instantiates a new text box with null name and value.
	 */
	public PasswordBox() {
		super();
	}
	

	/* (non-Javadoc)
	 * @see br.com.felix.fwt.ui.Input#write(java.io.PrintWriter)
	 */
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		if(!authorized()) return;
		PresentationMode pMode = getPresentationMode();
		switch(pMode){
			case EDIT:
				out.write("\n<input type=\"password\"");
				out.write(" name=\"");
				out.write(getName());

				out.write("\" value=\"");
				String value = getValue();
				if(value!=null)out.write(value);
				out.write("\"");
				if(style!=null)out.write(style);
				out.write(" />");
				break;
			case SHOW:
				out.write("********");
		}
	}


	@Override
	public String toString() {
		return getName();
	}

	
}
